local jueyan = fk.CreateSkill {

  name = "joy__jueyan",

  tags = {  },

}



jueyan:addEffect("active", {
  name = "joy__jueyan",
  can_use = function (self, player)
    if player:usedSkillTimes(jueyan.name, Player.HistoryPhase) == 0 then
      local slots = player:getAvailableEquipSlots()
      return table.contains(slots, Player.WeaponSlot) or table.contains(slots, Player.ArmorSlot) or
      (table.contains(slots, Player.OffensiveRideSlot) and table.contains(slots, Player.DefensiveRideSlot))
    end
  end,
  card_filter = Util.FalseFunc,
  card_num = 0,
  target_num = 0,
  interaction = function(self,player)
    local slots = player:getAvailableEquipSlots()
    local choices = {}
    if table.contains(slots, Player.WeaponSlot) then table.insert(choices, "WeaponSlot") end
    if table.contains(slots, Player.ArmorSlot) then table.insert(choices, "ArmorSlot") end
    if table.contains(slots, Player.OffensiveRideSlot) and table.contains(slots, Player.DefensiveRideSlot) then
      table.insert(choices, "RideSlot")
    end
    if #slots == 0 then return end
    return UI.ComboBox {choices = choices}
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local choice = self.interaction.data
    if choice == "RideSlot" then
      choice = {Player.OffensiveRideSlot, Player.DefensiveRideSlot}
    end
    room:abortPlayerArea(player, choice)
    if player.dead then return end
    if choice == 'WeaponSlot' then
      room:addPlayerMark(player, MarkEnum.SlashResidue.."-turn", 3)
    elseif choice == 'ArmorSlot' then
      room:addPlayerMark(player, MarkEnum.AddMaxCardsInTurn, 3)
      player:drawCards(3, jueyan.name)
    else
      room:addPlayerMark(player, "jueyan_distance-turn")
      if player:isWounded() then
        room:recover { num = 1, skillName = jueyan.name, who = player, recoverBy = player}
      end
      if not player:hasSkill("ex__jizhi",true) then
        room:handleAddLoseSkills(player, "ex__jizhi", nil, false)
        room.logic:getCurrentEvent():findParent(GameEvent.Turn):addCleaner(function()
          room:handleAddLoseSkills(player, "-ex__jizhi", nil, false)
        end)
      end
    end
  end,
})

jueyan:addEffect("targetmod", {
  name = "#joy__jueyan_targetmod",
  bypass_distances = function(self, player, skill, card, to)
    return player:getMark("jueyan_distance-turn") > 0
  end,
})

return jueyan